Load Pin-min data


In [1]:
Pdmin = 0.9
Pfa = 0.1
Att = 71.53 - 40

In [2]:
import glob
import re

def get_ccdf(x):
    
    xs = array(x)
    xs.sort()
    N = float(len(xs))
    P = arange(N)/N
    
    return xs, P

def get_gamma0(gammaN):
    
    gammaN, Pd = get_ccdf(gammaN)
    gamma0 = interp(1. - Pfa, Pd, gammaN)
    
    return gamma0

def iterate_campaign(path):
    for fn in glob.glob(path):
        g = re.search("_m([0-9_]+)dbm\.dat$", fn)
        if g:
            Pg = -float(g.group(1).replace('_', '.'))
            gamma = loadtxt(fn)
            
            yield Pg, gamma

def get_campaign_g(path, gamma0):
    Pg = []
    Pd = []
    
    for Pg0, gamma in iterate_campaign(path):
        Pg.append(Pg0)
        Pd.append(mean(gamma > gamma0))
            
    Pg = array(Pg)
    Pd = array(Pd)
    
    Pga = Pg.argsort()
    Pd = Pd[Pga]
    Pg = Pg[Pga]
    
    return Pg, Pd
            
def get_campaign(path, gamma0):
    Pg, Pd = get_campaign_g(path, gamma0)
    
    Pin = Pg - Att
    
    return Pin, Pd

def get_Pinmin(path, Pdth=Pdmin):
    gamma0 = None
    
    for fn in glob.glob(path):
        if fn.endswith("_off.dat"):
            gammaN = loadtxt(fn)
            gamma0 = get_gamma0(gammaN)
            break
            
    Pin, Pd = get_campaign(path, gamma0)
    
    Pinmin = interp(Pdth, Pd, Pin)
    
    return Pinmin

def get_method_ps(glob_path):
    method_ps = set()
    for path in glob.glob(glob_path):
        g = re.search("ks_(.*)_m", path)
        if g:
            method_ps.add(g.group(1))
        
    return sorted(method_ps)

def get_batch_Pinmin_permethod(path, Pdth=Pdmin):
    
    method_ps = get_method_ps(path)
    
    Pinmin_permethod = {}
    for method_p in method_ps:
        path2 = path.replace("*", "%s_*" % (method_p,))
        Pinmin_permethod[method_p] = get_Pinmin(path2, Pdmin)
        
    return Pinmin_permethod

Pinmin_permethod = get_batch_Pinmin_permethod("../measurements/pd/usrp/sim_usrp_micsoft_fs2mhz_Ns25ks_*.dat")

In [3]:
Pinmin_permethod


Out[3]:
{'agm_l10': -110.00804878048781,
 'agm_l15': -110.80891156462584,
 'agm_l20': -111.29923076923077,
 'agm_l5': -108.15111801242236,
 'cagm_l10': -118.88175879396985,
 'cagm_l15': -119.85467532467533,
 'cagm_l20': -120.43654205607477,
 'cagm_l5': -117.59405693950178,
 'cav_l10': -107.64843711843712,
 'cav_l15': -107.76201856148492,
 'cav_l20': -107.94666666666667,
 'cav_l5': -105.94322314049587,
 'ccav_l10': -118.53993377483444,
 'ccav_l15': -119.61591065292096,
 'ccav_l20': -120.17233576642336,
 'ccav_l5': -116.68298507462687,
 'ccfn_l10': -116.91823529411765,
 'ccfn_l15': -116.86663366336634,
 'ccfn_l20': -117.59993006993007,
 'ccfn_l5': -116.67569536423841,
 'ceme_l10': -114.50029702970298,
 'ceme_l15': -113.7142105263158,
 'ceme_l20': -113.28806451612904,
 'ceme_l5': -115.68111111111111,
 'cfn_l10': -107.69863406408095,
 'cfn_l15': -108.61428571428571,
 'cfn_l20': -108.71450184501845,
 'cfn_l5': -105.75935779816514,
 'cmac_l10': -119.35407407407408,
 'cmac_l15': -120.00770700636943,
 'cmac_l20': -120.19129032258064,
 'cmac_l5': -118.33,
 'cmet_l10': -118.08056179775281,
 'cmet_l15': -119.48049504950495,
 'cmet_l20': -119.8995652173913,
 'cmet_l5': -116.82893238434164,
 'cmme_l10': -117.83078125,
 'cmme_l15': -118.7675,
 'cmme_l20': -119.19666666666667,
 'cmme_l5': -117.07320987654322,
 'ed': -115.5748717948718,
 'eme_l10': -113.701875,
 'eme_l15': -113.08140186915888,
 'eme_l20': -112.75314049586777,
 'eme_l5': -114.87375,
 'mac_l10': -107.79455026455027,
 'mac_l15': -107.79455026455027,
 'mac_l20': -107.79455026455027,
 'mac_l5': -107.77096385542168,
 'met_l10': -104.5806863780359,
 'met_l15': -105.59451612903226,
 'met_l20': -105.5915866388309,
 'met_l5': -103.6302004008016,
 'mme_l10': -107.44743119266055,
 'mme_l15': -107.56817733990148,
 'mme_l20': -107.06763440860215,
 'mme_l5': -107.717265917603,
 'scf_Np128': -114.23114942528736,
 'scf_Np64': -114.29086956521739}

Load benchmark data


In [4]:
def get_benchmark_data():  
    Ns = 25000

    time_permethod = {}

    for line in open("../measurements/benchmark/benchmark-ninestein.dat"):
        g = re.match("(.*\))\s+(\d+)\s+([0-9.]+)", line)
        if not g:
            print "corrupted:", line
            continue 

        method = g.group(1)
        Ns0 = int(g.group(2))
        time0 = float(g.group(3))
        
        slug = method.lower()
        slug = re.sub(r"detector\(l=(\d+)\)", r"_l\1", slug)
        slug = re.sub(r"scfdetector\(np=(\d+), l=\d+\)", r"scf_Np\1", slug)
        slug = re.sub(r"energydetector\(\)", "ed", slug)

        if Ns0 == Ns:
            time_permethod[slug] = time0
            
    return time_permethod

time_permethod = get_benchmark_data()

In [5]:
time_permethod


Out[5]:
{'agm_l10': 630.178452,
 'agm_l15': 839.998722,
 'agm_l20': 1057.169437,
 'agm_l5': 427.081585,
 'cav_l10': 560.979843,
 'cav_l15': 754.089355,
 'cav_l20': 947.539806,
 'cav_l5': 368.788242,
 'cfn_l10': 559.201241,
 'cfn_l15': 752.840042,
 'cfn_l20': 943.319798,
 'cfn_l5': 367.41972,
 'ed': 35.200119,
 'eme_l10': 701.358318,
 'eme_l15': 909.209251,
 'eme_l20': 1123.421192,
 'eme_l5': 496.139526,
 'mac_l10': 560.16922,
 'mac_l15': 751.252174,
 'mac_l20': 942.530632,
 'mac_l5': 367.55085,
 'met_l10': 625.538826,
 'met_l15': 834.891796,
 'met_l20': 1048.629284,
 'met_l5': 421.900749,
 'mme_l10': 621.30928,
 'mme_l15': 830.099583,
 'mme_l20': 1044.092178,
 'mme_l5': 417.27066,
 'scf_Np128': 1518876.330853,
 'scf_Np64': 596789.758205}

Make arrays


In [6]:
#method = []
#methodtime = []
#methodPinmin = []
#mclass = []

from collections import defaultdict

methodtime = defaultdict(list)
methodPinmin = defaultdict(list)

for m in Pinmin_permethod.keys():
    
    Pinmin = Pinmin_permethod[m]    
    if m not in time_permethod:
        #continue
        m2 = re.sub("^c(..._l)", r"\1", m)        
    else:
        m2 = m

    t = time_permethod[m2]/time_permethod['ed']
    
    if 'ed' in m:
        c = 'ed'
    elif 'scf' in m:
        c = 'scf'
    elif re.match("c..._l", m):
        if 'cav' in m or 'cfn' in m or 'mac' in m:
            c = 'ccbd'
        else:
            c = 'cebd'
    elif 'cav' in m or 'cfn' in m or 'mac' in m:
        c = 'cbd'
    else:
        c = 'ebd'
        
    methodtime[c].append(t)
    methodPinmin[c].append(Pinmin)
    
    #mclass.append(c)
    #method.append(m)
    #methodtime.append(t)
    #methodPinmin.append(Pinmin)

Plot


In [7]:
#scatter(methodtime, methodPinmin, s=100, c=mclass)

#figure(figsize=(10, 8))
ms=10
mfc=(.8,.8,.8)
mew=1
plot(methodtime['ed'], methodPinmin['ed'], 'o', label='energy', ms=ms, mfc=mfc, mew=mew)
plot(methodtime['cbd'], methodPinmin['cbd'], '^', label='covariance', ms=ms, mfc=mfc, mew=mew, zorder=3)
plot(methodtime['ebd'], methodPinmin['ebd'], '^', label='eigenvalue', ms=ms, mfc='w', mew=mew)
#plot(methodtime['ccbd'], methodPinmin['ccbd'], 'v', label='covariance\n(with noise comp.)', ms=ms*.5, mfc='k', mew=mew, mec='k')
#plot(methodtime['cebd'], methodPinmin['cebd'], 'v', label='cov. eigenvalue\n(with noise comp.)', ms=ms*.5, mfc='w', mew=mew, mec='k')
plot(methodtime['scf'], methodPinmin['scf'], 's', label='cyclostationary', ms=ms, mfc=mfc, mew=mew)
xlabel("$t_{CPU}$ [relative to energy detection]")
ylabel("$P_{in}$ [dBm] @ $P_d = 0.9$")
xscale('log')
axis([.4, 1e5, -120, -100])
legend(ncol=1)
title("USRP @ $f_s=2$MHz, $N_s=25$ksamples")
grid()
savefig("time_pin_min_comparison.eps")



In [7]:


In [7]: